package com.cpi.cornpp.instructionstypes.converter;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import com.cpi.cornpp.common.exception.CornPPException;
import com.cpi.cornpp.instructionstypes.dto.InstructionsTypesDTO;
import com.cpi.cornpp.instructionstypes.exception.InstructionsTypesException;
import com.cpi.cornpp.instructionstypes.view.InstructionsTypesView;

/**
 * Instructions Types Converter
 * @author Edgar Joao
 *
 */
public class InstructionsTypesConverter {
  /**
   * Instructions Types Converter DTO to View	
   * @param dto
   * @return
   * @throws InstructionsTypesException
   */
  public InstructionsTypesView converterInstructionsTypesDtoToView(InstructionsTypesDTO dto) throws InstructionsTypesException{
	  InstructionsTypesView instructionsTypesView = null;
	  try{
		if(dto != null){
			instructionsTypesView = new InstructionsTypesView();
			instructionsTypesView.setId(dto.getInstructionTypeId());
			instructionsTypesView.setShortName(dto.getShortName());
			instructionsTypesView.setDescription(dto.getDescription());
		}
	  }catch( Exception exception ){
		InstructionsTypesException instructionsTypesException=null;
		exception.printStackTrace(System.out);
		instructionsTypesException = new InstructionsTypesException(exception , CornPPException.LAYER_CONVERTER,CornPPException.ACTION_LISTS);
		throw instructionsTypesException;
	  }
	  return instructionsTypesView;
  }
  /**
   * Converter List DTO to Views
   * 
   * @param instructionsTypesDTOs
   * @return
   * @throws InstructionsTypesException
   */
  public List convertDTOsToViews(List instructionsTypesDTOs) throws InstructionsTypesException{
		List instructionsTypesViews = null;		
		Iterator iterator = null;
		InstructionsTypesDTO instructionsTypesDTO = null;
		InstructionsTypesView instructionsTypesView = null;		
		try{
			instructionsTypesViews = new ArrayList(0);
			iterator = instructionsTypesDTOs.iterator();
			while(iterator.hasNext()){
				instructionsTypesDTO = (InstructionsTypesDTO) iterator.next();
				instructionsTypesView = converterInstructionsTypesDtoToView(instructionsTypesDTO);
				instructionsTypesViews.add(instructionsTypesView);
			}			
		}catch(Exception exception){
			InstructionsTypesException instructionsTypesException = null;
			exception.printStackTrace(System.out);
			instructionsTypesException = new InstructionsTypesException(exception , CornPPException.LAYER_CONVERTER,CornPPException.ACTION_LISTS);
			throw instructionsTypesException;
		}		
		return instructionsTypesViews;
	}

}
